package com.zygh.policeasset.utils;

import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.zygh.policeasset.pojo.Assets;
import com.zygh.policeasset.pojo.Completed;
import com.zygh.policeasset.pojo.Contract;
import com.zygh.policeasset.pojo.DailyProject;
import com.zygh.policeasset.pojo.DepRate;
import com.zygh.policeasset.pojo.FinalStatement;
import com.zygh.policeasset.pojo.Project;
import com.zygh.policeasset.pojo.PurchaseCodeInfo;
import com.zygh.policeasset.pojo.QrCodeInfo;
import com.zygh.policeasset.pojo.Settlement;
import com.zygh.policeasset.pojo.Tender;
import com.zygh.policeasset.pojo.imports.QrCodeInfoImport;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/utils/EasyExcelUtil.class */
public class EasyExcelUtil {
    private static String exportUrl;
    @Value("${nginx.url}")
    String nginxUrl;

    @Value("${file.export}")
    public void setExportUrl(String exportUrl2) {
        exportUrl = exportUrl2;
    }

    public void findFile() {
        System.out.println(exportUrl);
        File file = new File(exportUrl);
        if (!file.exists() && !file.isDirectory()) {
            System.out.println("//不存在");
            file.mkdir();
        }
    }

    public String easyExcelProject(String filename, HttpServletResponse response, List<Project> list1, List<Project> list2, List<Project> list3) throws IOException {
        try {
            findFile();
            String fileName = filename + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list1, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "基础项目").head(Project.class)).build());
            excelWriter.write(list2, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(1, "智能项目").head(Project.class)).build());
            excelWriter.write(list3, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(2, "采购项目").head(Project.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String easyExcelTender(String filename, HttpServletResponse response, List<Tender> list1, List<Tender> list2, List<Tender> list3) throws IOException {
        try {
            findFile();
            String fileName = filename + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list1, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "基础项目").head(Tender.class)).build());
            excelWriter.write(list2, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(1, "智能项目").head(Tender.class)).build());
            excelWriter.write(list3, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(2, "采购项目").head(Tender.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String easyExcelContract(String filename, HttpServletResponse response, List<Contract> list1, List<Contract> list2, List<Contract> list3) throws IOException {
        try {
            findFile();
            String fileName = filename + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list1, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "基础项目").head(Contract.class)).build());
            excelWriter.write(list2, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(1, "智能项目").head(Contract.class)).build());
            excelWriter.write(list3, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(2, "采购项目").head(Contract.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String easyExcelCompleted(String filename, HttpServletResponse response, List<Completed> list1, List<Completed> list2, List<Completed> list3) throws IOException {
        try {
            findFile();
            String fileName = filename + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list1, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "基础项目").head(Completed.class)).build());
            excelWriter.write(list2, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(1, "智能项目").head(Completed.class)).build());
            excelWriter.write(list3, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(2, "采购项目").head(Completed.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String easyExcelSettlement(String filename, HttpServletResponse response, List<Settlement> list1, List<Settlement> list2, List<Settlement> list3) throws IOException {
        try {
            findFile();
            String fileName = filename + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list1, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "基础项目").head(Settlement.class)).build());
            excelWriter.write(list2, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(1, "智能项目").head(Settlement.class)).build());
            excelWriter.write(list3, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(2, "采购项目").head(Settlement.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String easyExcelFinalStatement(String filename, HttpServletResponse response, List<FinalStatement> list1, List<FinalStatement> list2, List<FinalStatement> list3) throws IOException {
        try {
            findFile();
            String fileName = filename + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list1, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "基础项目").head(FinalStatement.class)).build());
            excelWriter.write(list2, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(1, "智能项目").head(FinalStatement.class)).build());
            excelWriter.write(list3, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(2, "采购项目").head(FinalStatement.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String deprateByTimeExport(String filename, HttpServletResponse response, List<DepRate> depRateList) throws IOException {
        try {
            findFile();
            String fileName = filename + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(depRateList, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, filename).head(DepRate.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String findByCompanyExcel(HttpServletResponse response, List<Project> projectList) {
        try {
            findFile();
            String fileName = "项目信息导出" + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(projectList, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "数据统计").head(Project.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String depratebytimeNewExport(HttpServletResponse response, List<DepRate> depRateList) {
        try {
            findFile();
            String fileName = "信息导出" + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(depRateList, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "数据统计").head(DepRate.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return this.nginxUrl + "assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String findallExcel(HttpServletResponse response, List<DailyProject> dailyProjectList) {
        try {
            findFile();
            String fileName = "项目信息导出" + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(dailyProjectList, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "数据统计").head(DailyProject.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String exportQrCode(HttpServletResponse response, List<QrCodeInfo> list) {
        try {
            findFile();
            String fileName = "二维码信息导出" + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "数据统计").head(QrCodeInfo.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return this.nginxUrl + "assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String exportQrCodePrintQrCode(HttpServletResponse response, List<QrCodeInfoImport> list) {
        try {
            findFile();
            String fileName = "二维码信息导出" + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "数据统计").head(QrCodeInfoImport.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String exportPurchaseCodeInfo(HttpServletResponse response, List<PurchaseCodeInfo> list) {
        try {
            findFile();
            String fileName = "二维码信息导出" + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "数据统计").head(PurchaseCodeInfo.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String exportAluminumQrCode(HttpServletResponse response, List<QrCodeInfo> list) {
        try {
            findFile();
            String fileName = "二维码信息导出" + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "数据统计").head(QrCodeInfo.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return "/assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    public String findAllExport(HttpServletResponse response, List<Assets> list) {
        try {
            findFile();
            String fileName = "资产信息导出" + DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
            OutputStream out = new FileOutputStream(exportUrl + fileName + ".xls");
            ExcelWriter excelWriter = EasyExcelFactory.getWriter(out);
            excelWriter.write(list, ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "数据统计").head(Assets.class)).build());
            excelWriter.finish();
            out.close();
            response.setContentType("text/html;charset=UTF-8");
            return this.nginxUrl + "assetsExcel/" + fileName + ".xls";
        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }
}